package com.aaa.cts.controller;

import com.aaa.cts.redission.DistributedRedisLock;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("redisson")
public class RedissonController {

    @Autowired
    private DistributedRedisLock distributedRedisLock;

    @GetMapping("/redder")
    @ApiOperation("redisson测试")
    public String redder(String key) throws IOException {
        //加锁
        distributedRedisLock.acquire(key);
        //执行具体业务逻辑
        System.out.println("执行业务逻辑");
        //释放锁
        distributedRedisLock.release(key);
        //返回结果
        return "sucess";
    }

}
